package com.kurumi.autoprint.service.impl.order;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kurumi.autoprint.bo.PageParam;
import com.kurumi.autoprint.mapper.mapper.print.PrintMrOrderMapper;
import com.kurumi.autoprint.service.order.PrintMrDetailService;



@Service
public class PrintMrDetailServiceImpl implements PrintMrDetailService {
	
	@Autowired
	private PrintMrOrderMapper printMrOrderMapper;

	@Transactional(readOnly = true)
	@Override
	public PageInfo<Map<String, Object>> getPrintDetailPageInfo(HttpServletRequest request, PageParam pageParam) {
		PageHelper.startPage(pageParam.getPage(), pageParam.getLimit());
		Map<String,Object> params = new HashMap<>();
		
		String start = request.getParameter("start");
		if(StringUtils.isNotEmpty(start)) {
			params.put("start", start);
		}
		
		String end = request.getParameter("end");
		if(StringUtils.isNotEmpty(end)) {
			params.put("end", end);
		}
		
		String ip = request.getParameter("ip");
		if(StringUtils.isNotEmpty(ip)) {
			params.put("ip", ip);
		}
		
		String idCard = request.getParameter("idCard");
		if(StringUtils.isNotEmpty(idCard)) {
			params.put("idCard", idCard);
		}
		
	
		List<Map<String,Object>> orderDetailList =  printMrOrderMapper.getPrintDetailList(params);
		PageInfo<Map<String,Object>> objectPageInfo = new PageInfo<>(orderDetailList);
		return objectPageInfo;
	}

	@Transactional(readOnly = true)
	@Override
	public Map<String, Object> getPrintDetailByOrderId(Integer orderId) {
		
		return printMrOrderMapper.getPrintDetailByOrderId(orderId);
	}

	
	@Transactional(readOnly = true)
	@Override
	public List<Map<String, Object>> getPrintDetailInfoByParams(HttpServletRequest request) {
		Map<String,Object> params = new HashMap<String,Object>();
		String start = request.getParameter("start");
		if(StringUtils.isNotEmpty(start)) {
			params.put("start", start);
		}
		
		String end = request.getParameter("end");
		if(StringUtils.isNotEmpty(end)) {
			params.put("end", end);
		}
		
		String ip = request.getParameter("ip");
		if(StringUtils.isNotEmpty(ip)) {
			params.put("ip", ip);
		}
		
		String idCard = request.getParameter("idCard");
		if(StringUtils.isNotEmpty(idCard)) {
			params.put("idCard", idCard);
		}
		
		return printMrOrderMapper.getPrintDetailInfoByParams(params);
	}
	
	



	

}
